package com.have.blog.web.controller;

import com.have.blog.base.wrapper.CommonPage;
import com.have.blog.base.wrapper.Wrapper;
import com.have.blog.web.dto.BlogSubjectDto;
import com.have.blog.web.dto.BlogSubjectItemDto;
import com.have.blog.web.service.BlogSubjectItemService;
import com.have.blog.web.service.BlogSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "专题相关接口", tags = {"专题相关接口"})
@RestController
@RequestMapping("/subject")
@Slf4j
public class BlogSubjectController {

    @Autowired
    private BlogSubjectService blogSubjectService;
    @Autowired
    private BlogSubjectItemService itemService;


    @ApiOperation(value = "获取专题列表", notes = "获取专题列表", response = String.class)
    @GetMapping("/getList")
    public Wrapper<CommonPage<BlogSubjectDto>> getList(@RequestParam(value = "pageNum", name = "pageNum", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize", name = "pageSize", defaultValue = "10") Integer pageSize) {
        log.info("获取博客专题 pageNum:{}, pageSize:{}", pageNum, pageSize);
        return blogSubjectService.getPgeList(pageNum, pageSize);
    }

    @ApiOperation(value = "获取专题Item列表", notes = "获取专题Item列表", response = String.class)
    @GetMapping("/getItemList")
    public Wrapper<CommonPage> getItemList(@RequestParam(value = "pageNum", name = "pageNum", defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize", name = "pageSize", defaultValue = "10") Integer pageSize,
                               @RequestParam(value = "subjectUid", name = "subjectUid", required = true) Integer subjectUid) {
        List<BlogSubjectItemDto> resultList = itemService.getListBySubjectUid(subjectUid, pageNum, pageSize);
        log.info("获取专题项目:{}", resultList.size());
        return Wrapper.success(CommonPage.restPage(resultList));
    }

}
